﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ServiceSATT;
using ApplicationContext;

namespace UI_SATT
{
    public partial class FrmNuevoArbitro : Form, IInterfazArbitro
    {
        public FrmNuevoArbitro()
        {
            InitializeComponent();
        }
        string ImplementaPersona = "PersonaService";
        string ImplementaArbitro = "ArbitroService";
        public static int DniArbitro;
        public FrmNuevoArbitro(string NombreDelClub)
        {
            InitializeComponent();
            this.TxtClub.Text = NombreDelClub;
        }

        #region IInterfazArbitro Members

        public int Dni
        {
            get
            {
                return int.Parse(TxtDniArbitro.Text);
            }
            set
            {
                TxtDniArbitro.Text=value.ToString();
            }
        }

        public string NombreClub
        {
            get
            {
               return TxtClub.Text;
            }
            set
            {
                TxtClub.Text = value; ;
            }
        }

        #endregion

        private void TxtDniArbitro_KeyPress(object sender, KeyPressEventArgs e)
        {
            
        }

        private void BtnAgregar_Click(object sender, EventArgs e)
        {
            Form NuevoArbitro = new FrmNuevoAfiliado("Arbitro",this);
            if (NuevoArbitro.ShowDialog() == DialogResult.OK)
            { this.TxtDniArbitro.Text = DniArbitro.ToString(); }
            this.DialogResult = DialogResult.OK;
        }

        private void BtnAceptar_Click(object sender, EventArgs e)
        {
            IArbitroService Arbitro = (IArbitroService)AppContext.Instance.GetObject(ImplementaArbitro);
            Arbitro.Agregar(this);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void TxtDniArbitro_TextChanged(object sender, EventArgs e)
        {

        }

        private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
        {

        }

        private void TxtDni_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                try
                {
                    IPersonaService persona = (IPersonaService)AppContext.Instance.GetObject(ImplementaPersona);

                    if (persona.ObtenerNombre(int.Parse(TxtDniArbitro.Text), "Arbitro") == "")
                    {
                        MessageBox.Show("El Dni Ingresado No Existe O No Corresponde A Un Arbitro");
                        BtnAgregar.Enabled = true;
                    }
                    else
                    {

                        BtnAgregar.Enabled = false;
                        LblOk.Visible = true;
                        this.Close();

                    }


                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                }
            }
        }

        private void BtnCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
